package com.golf.client.ui.applet;

import java.applet.Applet;
import java.awt.Canvas;

import com.golf.client.course.renderer.CompositeRenderer;
import com.golf.client.course.renderer.CourseRenderer;
import com.golf.client.course.renderer.InteractivePlayerRenderer;
import com.golf.client.player.InteractivePlayer;
import com.golf.client.ui.MainLoop;
import com.golf.core.course.Course;
import com.golf.core.course.bodies.Ball;
import com.golf.core.course.exceptions.CourseLoadException;
import com.golf.core.course.loader.CourseLoader;
import com.golf.server.engine.phys.Engine;

/**
 * 
 * 
 * @author gfloodgate
 */
public class GolfApplet extends Applet 
{
	
	/** <code>serialVersionUID</code> for this class. */
	private static final long serialVersionUID = -2076389864432033057L;

	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void init() 
	{
		super.init();
		
		Canvas canvas = new Canvas();
		canvas.setSize(600, 300);

		this.add(canvas);
		setSize(600,300);
		
		
        try
        {
            Course c = CourseLoader.load("course.xml");
            final Engine e = new Engine(c);
            
            
            InteractivePlayer p = new InteractivePlayer("bob", e, new Ball("playerball", c.getStartPosition()));
            canvas.addMouseListener(p);
            canvas.addMouseMotionListener(p);
            canvas.addMouseWheelListener(p);
            
            final CompositeRenderer renderer = new CompositeRenderer(canvas);
            renderer.addLayerRenderer(new CourseRenderer(c));
    		renderer.addLayerRenderer(new InteractivePlayerRenderer(p));
    
    		
    		final Thread loop = new Thread(new MainLoop(e, renderer));
    		loop.setPriority(Thread.NORM_PRIORITY);
    		loop.start();
        }
        catch (CourseLoadException e1)
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
		
	}

	// TODO: override stop.
	

}
